﻿CREATE VIEW usix.v_CustomerFile_Export_05
AS
SELECT     ISNULL(CF_E.ApplID, 0) AS ApplID, CF_E.DPD AS DaysPastDue, CF_E.LoanID, CF_E.[Customer #], CF_E.[Open Field#01], CONVERT(varchar, 
                      CF_E.CompanyID_Raw) + CF_E.[Customer #] AS VantageID, CF_E.VIN, CF_E.Serial#, CF_E.[G_L Date], DATEDIFF(dd, CF_E.[G_L Date], GETDATE()) 
                      AS GL_Days, CF_E.[Open Date], CASE WHEN [Car Year] > 100 THEN [car year] ELSE [car year] + 1900 END AS [Car Year], CF_E.Make, CF_E.Model, 
                      CF_E.[Pymnt Schedule], CF_E.[# of Payments], CF_E.[# of PaymentsM], CF_E.[Payment Amount], CF_E.[Total Payments], CF_E.[1st_ Payment Date], 
                      CF_E.FirstPaymentDateCalc, CF_E.[Last Payment Date], CF_E.[Next Payment Date], CF_E.[# Pmts Remaining], CF_E.[# Pmts RemainingM], 
                      CF_E.[Balance Remaining], CF_E.[Total Sales Price], CF_E.[Finance Charges], CF_E.[Status Code], CF_E.P_O_E_, CF_E.Loan#_Comments, 
                      CF_E.[Primary SSN], CF_E.[Amt_ Fin__Disc_ Amt], CF_E.[Interest Income], CF_E.[Earned Discount], CF_E.[Dealer Discount], CF_E.[Dealer Proceed], 
                      CF_E.[Dealer Code], usix.t_Dealer.Name AS Dealer, usix.t_Dealer.[Phone #] AS DealerPhone, CF_E.[Principal Balance], CF_E.APR, CF_E.Mileage, 
                      CF_E.[Collector Id#], CF_E.[Discount%], CF_E.[Origination State Code], CF_E.Portfolio#, CF_E.[Sales Rep_], CF_E.[Investor Client], CF_E.[Date L_C], 
                      CF_E.[Joint Name], CF_E.[Joint Address], CF_E.[Joint City], CF_E.[Joint State], CF_E.[Joint Zipcode], CF_E.[Joint SSN], CF_E.[Joint H Phone#], 
                      CF_E.[Joint W Phone#], CF_E.[Joint Cell#], CF_E.[Partial Payment], CF_E.[NSF Balance], CF_E.[Late Chg Bal], CF_E.[Apply Late Fee], CF_E.Branch#, 
                      CF_E.CompanyID, CF_E.CompanyID_Raw, CF_E.CompanyName, CF_E.[Bankruptcy Filed Y_N?], CF_E.[Bankruptcy Type 07_13?], 
                      CF_E.[Total Principal], CF_E.DPD, CF_E.DPD0, CF_E.DSLP, CF_E.LatePmtsCount * CF_E.[Payment Amount] AS PastDuePayments, 
                      CF_E.LatePmtsCount * CF_E.[Payment Amount] - CASE WHEN CF_E.LatePmtsCount > 0 THEN ISNULL(CF_E.[Partial Payment], 0) 
                      ELSE 0 END + ISNULL(CF_E.LateCharges, 0) + ISNULL(CF_E.[NSF Balance], 0) + ISNULL(CF_E.[Late Chg Bal], 0) AS PastDueAmount, 
                      CF_E.PaymentsMade, CF_E.PaymentsMadeM, CF_E.PaymentsExpectedM, CASE WHEN [status code] IN ('O', 'L') 
                      THEN CF_E.PaymentsExpectedM - CF_E.PaymentsMadeM ELSE 0 END AS PaymentsBehindM, CF_E.DownPayment, CF_E.[Princ/ChOff Ballance], 
                      CF_E.[Repo Date], CF_E.[A_R Balance], CF_E.[Resale Amt_], CF_E.Chargeoff, CF_E.[Final Repo Date], CF_E.Retainage, CF_E.[Other Chgs Bal], 
                      CF_E.UsixID, ISNULL(CF_E.[Title Received Y_N?], 'N') AS [Title Received Y_N?], CF_E.NDay, CF_E.DPDCalc, CF_E.[Simple_Add-On], CF_E.VINCheck, 
                      CF_E.LateCharges, CF_E.LatePmtsCount, CF_E.RemBalance78, ISNULL(CF_E.[Total Principal], 0) + ISNULL(CF_E.DSLP * CF_E.PerDiem, 0) 
                      + ISNULL(CF_E.LateCharges, 0) + ISNULL(CF_E.[NSF Balance], 0) AS PayOff_TP, 
                      CASE [Simple_Add-On] WHEN 'S1' THEN [Total Principal] + DSLP * PerDiem ELSE RemBalance78 END + CF_E.LateCharges + CF_E.[NSF Balance] AS PayOff_Calc,
                       CF_E.PerDiem, usix.t_PaymentNSF.[Payment Date] AS NSF_Date, ISNULL(usix.t_PaymentNSF.Count, 0) AS NSF_Count, 
                      ISNULL(usix.t_PaymentNSF.[Payment Amount], 0) AS NSF_Amount, DATEDIFF(dd, usix.t_PaymentNSF.[Payment Date], GETDATE()) AS NSF_DaysSince, 
                      CF_E.PaymentsMadeByPrinBal, CF_E.NameLast, CF_E.NameFirst, dbo.tzip_Counties_ALL.CountyName AS County, CF_E.PaymentAmountM, 
                      ISNULL(dbo.v_DefermentsInOneYear.Count, 0) AS DefermentsCount, CF_E.St, LEFT(CF_E.[Zip Code], 5) AS [Zip Code]
FROM         dbo.v_DefermentsInOneYear RIGHT OUTER JOIN
                      usix.t_CustomerFile_Export AS CF_E ON dbo.v_DefermentsInOneYear.CompanyID = CF_E.CompanyID_Raw AND 
                      dbo.v_DefermentsInOneYear.[Id #] = CF_E.UsixID LEFT OUTER JOIN
                      dbo.tzip_99 LEFT OUTER JOIN
                      dbo.tzip_Counties_ALL ON dbo.tzip_99.COUNTY = dbo.tzip_Counties_ALL.CountyFIPS AND dbo.tzip_99.STATE = dbo.tzip_Counties_ALL.StateFIPS ON 
                      LEFT(CF_E.[Zip Code], 5) = dbo.tzip_99.ZIP_CODE LEFT OUTER JOIN
                      usix.t_PaymentNSF ON CF_E.CompanyID_Raw = usix.t_PaymentNSF.CompanyID AND CF_E.UsixID = usix.t_PaymentNSF.[Id #] LEFT OUTER JOIN
                      usix.t_Dealer ON CF_E.CompanyID_Raw = usix.t_Dealer.CompanyID AND CF_E.[Dealer Code] = usix.t_Dealer.[Dealer Code]

GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[36] 4[35] 2[10] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "v_DefermentsInOneYear"
            Begin Extent = 
               Top = 22
               Left = 105
               Bottom = 115
               Right = 256
            End
            DisplayFlags = 344
            TopColumn = 0
         End
         Begin Table = "CF_E"
            Begin Extent = 
               Top = 6
               Left = 423
               Bottom = 314
               Right = 622
            End
            DisplayFlags = 280
            TopColumn = 36
         End
         Begin Table = "tzip_99"
            Begin Extent = 
               Top = 54
               Left = 703
               Bottom = 162
               Right = 854
            End
            DisplayFlags = 344
            TopColumn = 0
         End
         Begin Table = "tzip_Counties_ALL"
            Begin Extent = 
               Top = 196
               Left = 666
               Bottom = 304
               Right = 817
            End
            DisplayFlags = 344
            TopColumn = 0
         End
         Begin Table = "t_PaymentNSF (usix)"
            Begin Extent = 
               Top = 81
               Left = 52
               Bottom = 189
               Right = 214
            End
            DisplayFlags = 344
            TopColumn = 0
         End
         Begin Table = "t_Dealer (usix)"
            Begin Extent = 
               Top = 150
               Left = 58
               Bottom = 258
               Right = 209
            End
            DisplayFlags = 344
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 111
         Width = 284', @level0type = N'SCHEMA', @level0name = N'usix', @level1type = N'VIEW', @level1name = N'v_CustomerFile_Export_05';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 5625
         Alias = 1155
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End', @level0type = N'SCHEMA', @level0name = N'usix', @level1type = N'VIEW', @level1name = N'v_CustomerFile_Export_05';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'usix', @level1type = N'VIEW', @level1name = N'v_CustomerFile_Export_05';

